package com.android.music.prolyric;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class setting_search extends Activity implements OnClickListener
{
	TextView scolorSong,scolorSinger,scolorId,scolorResult;
	ImageView sbgr;
	AmbilWarnaDialog dialog;
	SharedPreferences shareColor;
	SharedPreferences.Editor editor;
	Button btnOk,btnCancel;	 
	int colorSong,colorSinger,colorId,imgBgr,colorResult;
	int defaultColor = 0xffffffff;
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_search);
		
		scolorSong = (TextView)findViewById(R.id.scolorSong);
		scolorSinger = (TextView)findViewById(R.id.scolorSinger);
		scolorId = (TextView)findViewById(R.id.scolorIdSong);	
		scolorResult = (TextView)findViewById(R.id.scolorResult);
		sbgr = (ImageView)findViewById(R.id.simgPlayer);
		btnOk = (Button)findViewById(R.id.sbtnOk);
		btnCancel = (Button)findViewById(R.id.sbtnCancel);
		
		scolorId.setOnClickListener(this);
		scolorSinger.setOnClickListener(this);
		scolorSong.setOnClickListener(this);		
		sbgr.setOnClickListener(this);
		btnOk.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
		scolorResult.setOnClickListener(this);
		
		SharedPreferences prefs = getSharedPreferences("searchColor", MODE_PRIVATE);
		
		colorSong= (int) prefs.getInt("songcolor",defaultColor);
		colorSinger= (int) prefs.getInt("singercolor",defaultColor);
		colorId=(int) prefs.getInt("idcolor",defaultColor);
		imgBgr = (int) prefs.getInt("sbgr",R.drawable.girl);
		colorResult=(int) prefs.getInt("resultcolor",defaultColor);
		
		scolorId.setBackgroundColor(colorId);
		scolorSinger.setBackgroundColor(colorSinger);
		scolorSong.setBackgroundColor(colorSong);
		scolorResult.setBackgroundColor(colorResult);
				
		sbgr.setBackgroundResource(imgBgr);
		
		shareColor = getSharedPreferences("searchColor", MODE_PRIVATE);
		editor = shareColor.edit();
		
		
		
	}
	public void onClick(View v) 
	{
		switch (v.getId()) 
		{
		case R.id.scolorIdSong:
			dialog = new AmbilWarnaDialog(setting_search.this,colorId, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					scolorId.setBackgroundColor(color);
					colorId=color;
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
		case R.id.scolorSong:
			dialog = new AmbilWarnaDialog(setting_search.this,colorSong, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					scolorSong.setBackgroundColor(color);
					colorSong=color;					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;
			
		case R.id.scolorSinger:
			dialog = new AmbilWarnaDialog(setting_search.this,colorSinger, new OnAmbilWarnaListener() {
				
				public void onOk(AmbilWarnaDialog dialog, int color) {
					scolorSinger.setBackgroundColor(color);
					colorSinger=color;					
				}
				
				public void onCancel(AmbilWarnaDialog dialog) {
					// TODO Auto-generated method stub				
				}
			});
			dialog.show();
			
			break;	
		case R.id.scolorResult:
			dialog = new AmbilWarnaDialog(setting_search.this,colorSinger, new OnAmbilWarnaListener() {
							
				public void onOk(AmbilWarnaDialog dialog, int color) {
					scolorResult.setBackgroundColor(color);
					colorResult=color;					
				}
							
				public void onCancel(AmbilWarnaDialog dialog) {
								// TODO Auto-generated method stub				
				}
			});
			dialog.show();
		
			
		case R.id.simgPlayer:
			startActivityForResult(new Intent(setting_search.this, setting_background.class),3000);	
			break;
		case R.id.sbtnOk:
			editor.putInt("idcolor",colorId);
			editor.putInt("songcolor", colorSong);
			editor.putInt("singercolor", colorSinger);	
			editor.putInt("resultcolor", colorResult);	
			editor.putInt("sbgr",imgBgr);
			editor.commit();
			Toast.makeText(setting_search.this, "Save data succeesful", Toast.LENGTH_LONG);
			
			break;
		case R.id.sbtnCancel:
			finish();
			break;

		default:
			break;
		}
		
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) 
	{
		if(requestCode==3000)
			if(resultCode==RESULT_OK)
			{
				imgBgr = Integer.parseInt(data.getData().toString());				
				sbgr.setBackgroundResource(imgBgr);
			}
	}
	
}
